<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/4/2 0002
 * Time: 17:13
 */
defined('BASEPATH') OR exit('No direct script access allowed');
include_once('./simple_html_dom.php');

class Jinyu extends CI_Controller
{
    public function types(){

        $url = "https://www.kingmed.com.cn/web/p_itemS.html";
        $content = geturl($url);
        $html = str_get_html($content);
        foreach($html->find('#fenlei',0)->find('li') as $ak=>$a)
        {
            $name = trim($a->find('span',1)->innertext);
            $ins_data['id'] = $ak+1;
            $ins_data['name'] = $name;
            echo $this->db->insert('jinyu_types',$ins_data);
            //echo $name;exit;
        }
    }

    public function info(){
        $content = file_get_contents('./jinyu');
        $infos = json_decode($content,true);
        $infos = $infos['dataList'];
        $types = $this->db->get('jinyu_types')->result_array();
        $types = array_combine(array_column($types,'id'),array_column($types,'name'));
        $sql = "";
        //$infos = array_slice($infos,0,5);
        foreach($infos as $vo){
            $yaoqiu = "<b>标本要求</b>：".$vo['SPECIMEN_REQUIREMENTS']."\n";
            $yaoqiu .= "<b>采样容器</b>：".$vo['SAMPLE_CONTAINER_NAME']."\n";
            $yaoqiu .= "<b>采集要求</b>：".$vo['SAMPLE_PREPARATION']."\n";
            $yaoqiu .= "<b>存放条件</b>：推荐".$vo['BF_DEFAULT_KEEP_DESC']."保存送检；保存稳定性：".$vo['STORAGE_TEMPERATURE_1'].$vo['SPECIMEN_STABILITY_PERIOD_1'].$vo['UNIT_TIME_1'].",".$vo['STORAGE_TEMPERATURE_2'].$vo['SPECIMEN_STABILITY_PERIOD_2'].$vo['UNIT_TIME_2'].",".$vo['STORAGE_TEMPERATURE_3'].$vo['SPECIMEN_STABILITY_PERIOD_3'].$vo['UNIT_TIME_3']."\n";
            $yaoqiu .= "<b>拒收标准</b>：".$vo['SPECIMEN_REJECT_DESC']."\n";
            $yaoqiu = addslashes($yaoqiu);
            $jiance_type = $types[$vo['ITEM_KIND_ID']];
            $name_c = addslashes($vo['TEST_ITEM_NAME_CN']);
            $name_e = addslashes($vo['TEST_ITEM_NAME_ALT_ENG']);
            $jibing = addslashes($vo['CLINICAL_TESTIFY_DESC']);
            $fangfa = addslashes($vo['TEST_METHOD_NAME']);
            $yiyi = addslashes($vo['CLINICAL_APPLICATION_DESC']);
            $beizhu = addslashes($vo['REMARKS']);
            $bieming = addslashes($vo['ITEM_NAME_ALIAS']);
            $id = $vo['ID'];
            $sql .= "(".$id.",'".$jiance_type."','".$name_c."','".$name_e."','".$jibing."','".$fangfa."','".$yaoqiu."','".$yiyi."','".$beizhu."','".$bieming."'),";
        }
        $sql = substr($sql,0,-1);
        $sql = 'INSERT ignore INTO ai_spider_kingmed_jiance(id,jiance_type,name_c,name_e,jibing,fangfa,yaoqiu,yiyi,beizhu,bieming) VALUES '.$sql;
        //echo $sql;exit;
        $this->db->query($sql);

    }
}